package com.example.yls.volley_picture;

import android.graphics.Bitmap;
import android.util.Log;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

/**
 * Created by yls on 2019/3/18.
 */

class MyImageCache implements ImageLoader.ImageCache {
    private static final String TAG ="MyImageCache" ;
    //LRU 最近最少使用
    private LruCache<String,Bitmap> lruCache;

    //实现缓存
    public MyImageCache(){
        int maxsize=10 * 1024 *1024;
        lruCache=new LruCache<String, Bitmap>(maxsize){
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return value.getRowBytes() * value.getHeight();
            }
        };
    }

    @Override
    public Bitmap getBitmap(String s) {
        Bitmap bitmap=lruCache.get(s);
        if(bitmap==null){
            Log.e(TAG,"getBitmap failed bitmap == null");
        }else {
            Log.e(TAG,"getBitmap success bitmap != null");
        }
        return bitmap;
    }

    @Override
    public void putBitmap(String s, Bitmap bitmap) {
        if(bitmap==null){
            Log.e(TAG,"putBitmap failed bitmap == null");
        }else {
            Log.e(TAG,"putBitmap success bitmap != null");
        }
        lruCache.put(s,bitmap);
    }
}
